/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.ad.restws;

/**
 *
 * @author sexta13
 */
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

@Path("/feedsreaderws")
public class FeedsreaderWs {

    private static Map<String, Stat> stats = new HashMap<String, Stat>();
    private StatsService statsService = new StatsService();


    //Estatisticas entre data inicio e data fim
    @GET
    @Path("/getStatsXML")
    @Produces("application/xml")
    public List<Stat> getStatsXML(@QueryParam("dateStart") long dateStart, @QueryParam("dateEnd") long dateEnd) {
        statsService = new StatsService();
        if (String.valueOf(dateStart).equals("0") && String.valueOf(dateEnd).equals("0")) {


            System.out.println("teste1: " + dateStart + " " + dateEnd);
            stats.put("1", statsService.devolveItemFeeds(0, 0));
            stats.put("2", statsService.devolveItemFeedsPartilhados());
            stats.put("3", statsService.devolveItemFeedsLidos());
            stats.put("4", statsService.devolveCategorias(0, 0));

        } else if (!String.valueOf(dateStart).equals("0") && String.valueOf(dateEnd).equals("0")) {
            System.out.println("teste2: " + dateStart + " " + dateEnd);
            stats.put("1", statsService.devolveItemFeeds(dateStart, 0));
            stats.put("4", statsService.devolveCategorias(dateStart, 0));


        } else {
            System.out.println("teste3: " + dateStart + " " + dateEnd);
            stats.put("1", statsService.devolveItemFeeds(dateStart, dateEnd));
            stats.put("4", statsService.devolveCategorias(dateStart, dateEnd));

        }


        return new ArrayList<Stat>(stats.values());
    }

    @GET
    @Path("/getStatsJSON")
    @Produces("application/json")
    public List<Stat> getStatsJSON(@QueryParam("dateStart") long dateStart, @QueryParam("dateEnd") long dateEnd) {
        statsService = new StatsService();
        if (String.valueOf(dateStart).equals("0") && String.valueOf(dateEnd).equals("0")) {


            System.out.println("teste1: " + dateStart + " " + dateEnd);
            stats.put("1", statsService.devolveItemFeeds(0, 0));
            stats.put("2", statsService.devolveItemFeedsPartilhados());
            stats.put("3", statsService.devolveItemFeedsLidos());
            stats.put("4", statsService.devolveCategorias(0, 0));

        } else if (!String.valueOf(dateStart).equals("0") && String.valueOf(dateEnd).equals("0")) {
            System.out.println("teste2: " + dateStart + " " + dateEnd);
            stats.put("1", statsService.devolveItemFeeds(dateStart, 0));
            stats.put("4", statsService.devolveCategorias(dateStart, 0));


        } else {
            System.out.println("teste3: " + dateStart + " " + dateEnd);
            stats.put("1", statsService.devolveItemFeeds(dateStart, dateEnd));
            stats.put("4", statsService.devolveCategorias(dateStart, dateEnd));

        }


        return new ArrayList<Stat>(stats.values());
    }
 
}
